class Solution {
public:
    int longestSubarray(vector<int>& nums) {
        int ans = 0, mx = 0, cnt = 0;
        for (int x : nums) {
            if (x > mx) {
                mx = x;
                ans = cnt = 1;
            }
            else if (x == mx) {
                cnt++;
                ans = max(ans, cnt);
            }
            else {
                cnt = 0;
            }
        }
        return ans;
    }
};